package com.guomao.demoi;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class JavaDemo2 {

    public static void main(String[] args) {


        List<String> names = List.of("admin", "root", "jack", "elise", "zuck", "annie", "yasuo");

        List<String> nums = List.of("100", "200", "200", "300");
        List<Integer> num = List.of(56, 88, 89, 1, 32);


        Stream<Integer> infiniteStream = Stream.iterate(0, n -> n + 2); // 无限偶数流
        infiniteStream.forEach(n -> System.out.println(n));
        Stream<Double> randomStream = Stream.generate(Math::random); // 无限随机数流

//        Stream<String> myname = names.stream();
//
//        Stream<String> stream = myname.filter(name -> name.length() > 3);
//
//        List<String> collect = stream.collect(Collectors.toList());
////        Set<String> collect1 = stream.collect(Collectors.toSet());
//
//        for (String s : collect) {
//            System.out.println(s);
//        }
//        num.stream().sorted().forEach(System.out::println);
//
//
//        Stream<String> stream1 = names.stream();
//        Stream<String> stream2 = nums.stream();
//
//        Stream<Object> empty = Stream.empty();

//        Stream.concat(stream1, stream2).forEach(System.out::println);

//        stream2.distinct().forEach(System.out::println);


        /*nums.stream().map((String s) -> {
            return Integer.parseInt(s) + 1000;
        }).forEach(System.out::println);*/

//        nums.stream().map(Integer::parseInt).forEach(System.out::println);
//        names.stream().filter(s -> s.contains("a")).forEach(System.out::println);
//        long count = names.stream().filter(s -> s.contains("a")).count();
//        names.stream().filter(s -> s.contains("a")).count();
//        System.out.println(count);

//        names.stream().filter(s -> s.length() > 4).forEach(System.out::println);
//        names.stream().filter(s -> s.length() > 4).limit(2).forEach(System.out::println);
//        names.stream().filter(s -> s.length() > 4).forEach(System.out::println);
//        names.stream().filter(s -> s.length() > 4).skip(2).forEach(System.out::println);

//        names.stream().filter(name -> name.length() > 4).map((String name, Person p) -> {
//            Person person = new Person(name, 20);
//            return person;
//        })

    }

}
